package com.loong.system.controller.backend;

import com.loong.common.mvc.BaseBackendController;
import com.loong.common.rest.Result;
import com.loong.common.validator.group.CommonInsert;
import com.loong.common.validator.group.CommonUpdate;
import com.loong.common.validator.group.CommonValidate;
import com.loong.system.common.backend.param.SystemPositionParam;
import com.loong.system.handler.SystemPositionHandler;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 配置位置控制器
 */
@RestController
@RequestMapping("/manage/system/position")
public class SystemPositionController extends BaseBackendController {

    @Resource
    private SystemPositionHandler systemPositionHandler;

    /**
     * @description: 保存位置
     * @param param
     * @return
     * @status done
     */
    @PostMapping("save")
    public Result save(@Validated(value = {CommonInsert.class, CommonValidate.class}) SystemPositionParam param){
        param.setId(null);
        return   handlerExecutor.execute(()->systemPositionHandler.save(param));
    }

    /**
     * @description: 更新位置信息
     * @param param
     * @return
     */
    @PostMapping("update")
    public Result update(@Validated(value = {CommonUpdate.class, CommonValidate.class}) SystemPositionParam param){
        return  handlerExecutor.execute(()->systemPositionHandler.update(param));
    }

    /**
     *删除位置及该节点下的所有节点
     * @param positionIds
     * @return
     */
    @PostMapping("delete")
    public Result delete(@RequestParam("positionIds") List<Long> positionIds){
        return  handlerExecutor.execute(()->systemPositionHandler.deleteByIds(positionIds));
    }

    /**
     *
     *  @description: 获取位置树
     * @return
     */
    @PostMapping("queryTree")
    public Result queryPositionTree(){
        return  handlerExecutor.execute(()->systemPositionHandler.queryAllPositionTree());
    }

}
